package com.timedomain.him.remake.ui;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.timedomain.him.remake.R;
import com.timedomain.him.remake.utils.BaseActivity;

import com.timedomain.him.remake.utils.DataPackManager;
import org.jetbrains.annotations.Nullable;

public class AboutActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        try {
            ((TextView)findViewById(R.id.txtAboutVersion)).setText("版本："+getPackageManager().getPackageInfo(getPackageName(),0).versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        ((TextView)findViewById(R.id.txtDataPackVersion)).setText("数据包版本："+ DataPackManager.getOfficialReleaseDataPack().version);
    }


    public void gotoBugReport(View view) {
        startActivity(new Intent(this,BugreportActivity.class));
    }

    public void gotoContributorPage(View view) {
        startActivity(new Intent(this,ContributorActivity.class));
    }

    public void checkForUpdate(View v){
        int versionCode = 0;
        String versionName = "";

        try {
            var pkgInfo = getPackageManager().getPackageInfo(getPackageName(),0);
            versionName = pkgInfo.versionName;
            versionCode = pkgInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }

        int datapackVersion = DataPackManager.getOfficialReleaseDataPack().version;

        String url = "https://himremake.zyfdroid.com/update.html?";
        url+="versioncode="+versionCode;
        url+="&versionname="+versionName;
        url+="&datapackversion="+datapackVersion;

        gotoUrl(url);

    }


}
